package com.demo1_两数之和;

import java.util.HashMap;

 class Solution_哈希方法 {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (!map.containsKey(target-nums[i])){
                map.put(nums[i],i);
            }else {
                Integer index = map.get(target - nums[i]);
                return new int[]{index,i};
            }
        }
        return null;
    }
}
